import { delRecordApi } from '@/api/system/record/record'
import { RecordParam } from '@/api/system/record/RecordModel'
import useInstance from '@/hooks/useInstance'
import { StatusCode } from '@/http/request'
import { reactive } from 'vue'

export default function useRecord(getRecordList: any) {
    const { global } = useInstance()

    // 删除
    const delBtn = async (id: number) => {
        console.log(global)
        const confirm = await global.$eleConfirm('确定删除该数据吗？')
        if (confirm) {
            // 执行删除操作
            const param = reactive<RecordParam>({
                id: id
            })
            let res = await delRecordApi(param)
            if (res && res.code == StatusCode.Success) {
                // 刷新列表
                getRecordList()
                // 信息提示
                global.$message({ message: res.msg, type: 'success' })
            }
        }
    }

    const fmtBody = (value: string) => {
        try {
            return JSON.parse(value)
        } catch (err) {
            return value
        }
    }

    return {
        delBtn,
        fmtBody
    }
}
